package com.bsj.travel.device.web.controller;

import com.bsj.travel.def.common.DTO.web.category.CategoryDTO;
import com.bsj.travel.def.common.DTO.web.category.CategorySearchDTO;
import com.bsj.travel.def.common.VO.CategoryVO;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.device.service.CategoryService;
import com.bsj.travel.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @description CategoryController
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/1/22 10:50
 **/
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 添加品类
     *
     * @param categoryDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/22 11:49
     */
    @PostMapping("/add")
    @RequiresPermissions(value = "category:operation:add")
    public JsonResult add(@Validated CategoryDTO categoryDTO) {
        return categoryService.addCategory(categoryDTO);
    }

    /**
     * 删除品类
     *
     * @param categoryId
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/22 11:49
     */
    @PostMapping("/delete/{categoryId}")
    @RequiresPermissions(value = "category:operation:delete")
    public JsonResult delete(@PathVariable Long categoryId) {
        return categoryService.deleteCategory(categoryId);
    }

    /**
     * 修改品类
     *
     * @param categoryDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/22 11:49
     */
    @PostMapping("/update")
    @RequiresPermissions(value = "category:operation:update")
    public JsonResult update(@Validated CategoryDTO categoryDTO) {
        return categoryService.updateCategory(categoryDTO);
    }

    /**
     * 根据品类id获取品类信息
     *
     * @param categoryId
     * @return com.bsj.travel.def.global.JsonResult<com.bsj.travel.def.common.VO.CategoryVO>
     * @author ljx
     * @time 2024/1/22 11:50
     */
    @GetMapping("/getById/{categoryId}")
    @RequiresPermissions(value = "category:info:getById")
    public JsonResult<CategoryVO> getById(@PathVariable("categoryId") Long categoryId) {
        CategoryVO categoryVO = categoryService.getCategoryInfoById(categoryId);
        return JsonResult.success(categoryVO);
    }

    /**
     * 品类分页
     *
     * @param categorySearchDTO
     * @return com.bsj.travel.def.global.JsonResult<java.util.List<com.bsj.travel.def.common.VO.CategoryVO>>
     * @author ljx
     * @time 2024/1/22 11:50
     */
    @GetMapping("/page")
    @RequiresPermissions(value = "category:info:page")
    public JsonResult<List<CategoryVO>> page(@Validated CategorySearchDTO categorySearchDTO) {
        return categoryService.pageCategory(categorySearchDTO);
    }

}
